
#include<iostream>
#include<string>
#include<vector>
using namespace std;

class Product		//抽象工厂类
{
public:
	virtual ~Product() {}
	virtual string Opertion() const = 0;
};

class ConcreteProductA : public Product		//具体工厂类
{
public:
	string Opertion() const override
	{
		return "ConcreteproductA";
	}
};

class ConcreteProductB : public Product		//具体工厂类
{
public:
	string Opertion() const override
	{
		return "ConcreteproductB";
	}
};


class Creator		//抽象产品类
{
public:
	virtual ~Creator() {}
	virtual Product* FactoryMethod() const = 0;
	string SomeOperation() const
	{
		Product* product = this->FactoryMethod();
		string result = product->Opertion();
		delete product;
		return result;
	}
};



class ConcreteCreatorA : public Creator		//具体产品类
{
public:
	Product* FactoryMethod() const override
	{
		return new ConcreteProductA();
	}
};


class ConcreteCreatorB : public Creator		//具体产品类
{
public:
	Product* FactoryMethod() const override
	{
		return new ConcreteProductB();
	}
};		


void ClientCode(const Creator& creator)
{ 
	cout << " Client: I am not aware of the creator's class, but it still works." << endl
		<< creator.SomeOperation() << endl;
}


int main()
{
	Creator* creator = new ConcreteCreatorA();
	ClientCode(*creator);
	cout << endl;
	creator = new ConcreteCreatorB();
	ClientCode(*creator);
	delete creator;
	
}


/*
 Client: I am not aware of the creator's class, but it still works.
ConcreteproductA

 Client: I am not aware of the creator's class, but it still works.
ConcreteproductB
*/










#include<iostream>
using namespace std;
//抽象工厂模式

//抽象产品类+具体产品类
// 基类 衣服
class Clothe
{
public:
	virtual void Show() = 0;
	virtual ~Clothe() {}
};

// 基类 鞋子
class Shoes
{
public:
	virtual void Show() = 0;
	virtual ~Shoes() {}
};

// 耐克衣服
class NiKeClothe : public Clothe
{
public:
	void Show()
	{
		std::cout << "我是耐克衣服，时尚我最在行！" << std::endl;
	}
};

// 耐克鞋子
class NiKeShoes : public Shoes
{
public:
	void Show()
	{
		std::cout << "我是耐克球鞋，让你酷起来！" << std::endl;
	}
};


//抽象工厂类 + 具体工厂类
// 总厂
class Factory
{
public:
	virtual Shoes* CreateShoes() = 0;
	virtual Clothe* CreateClothe() = 0;
	virtual ~Factory() {}
};

// 耐克生产者/生产链
class NiKeProducer : public Factory
{
public:
	Shoes* CreateShoes()
	{
		return new NiKeShoes();
	}

	Clothe* CreateClothe()
	{
		return new NiKeClothe();
	}
};



int main()
{
	// ================ 生产耐克流程 ==================== //
	// 鞋厂开设耐克生产线
	Factory* niKeProducer = new NiKeProducer();

	// 耐克生产线产出球鞋
	Shoes* nikeShoes = niKeProducer->CreateShoes();
	// 耐克生产线产出衣服
	Clothe* nikeClothe = niKeProducer->CreateClothe();

	// 耐克球鞋广告喊起
	nikeShoes->Show();
	// 耐克衣服广告喊起
	nikeClothe->Show();

	// 释放资源
	delete nikeShoes;
	delete nikeClothe;
	delete niKeProducer;


	return 0;
}


/*
我是耐克球鞋，让你酷起来！
我是耐克衣服，时尚我最在行！
*/
